1. Field of the Invention
The present invention relates to a method, system, and program for a query predicate generator to construct a database query predicate from received query conditions.
2. Description of the Related Art
Many users access information in a database using a database search graphical user interface (GUI) having fields in which the user may enter search terms to search data attributes or fields in the database. For instance, in some implementations, a user interface panel is displayed to allow the user to construct a query to submit to the database to search, where each query includes zero or more query conditions that are comprised of a database attribute a comparison operator (e.g., equals, not equals, greater than, less than, etc.), and a comparison value for the attribute. The generated database query typically includes a list of attributes (columns) that define what is included in each record to retrieve from the database and a predicate that qualifies the records to be included in the results of the query. The database server evaluates the predicate for every record (row) in the search space (table/view) and returns the records that satisfy the predicate to the client. Each condition in the predicate qualification may eliminate zero or more records from the candidate set. After the database determines that a record does not satisfy a predicate, it moves on to the next candidate record.
Some database search GUIs include drop down menus from which the user may select attributes to search and conditions for those attributes. The comparison value may be entered in a separate field or also may be selected from a drop down menu if there are a limited number of possible values for the database attribute.
Other database search GUIs allow the user to construct a query predicate by entering one or more search terms to cause the database search engine to search all database attributes for the specified search terms.
Some database search GUIs further allow the user to specify logical operators between query predicate conditions, such as AND, OR, etc. to further instruct the database search engine on how to generate the database query to use to search the database. Some database search GUIs allow the user to enter the logical operator between filter conditions by entering terms such as AND, OR, +, or no operator to specify the OR operator. Other database search GUIs provide drop down menus, select boxes, or other GUI elements to allow the user to select a predefined logical operator to use between the filter conditions (e.g.: “any of these” versus “all of these” selection). Other database search GUIs provide means to control the order of operation for evaluating the query conditions in the predicate such as explicitly creating parenthesized groups and joining them with logical operators.
All the above GUI mentioned panels assist users in constructing a proper search. Without the use of such panels, a user would have to write a program including database search queries, such as Structured Query Language (SQL) statements. Typically, the database search GUIs that provide more advanced control with regards to order of precedence and/or logical operators are more difficult to use because they require the user to understand how to properly form the logical expressions associated with crafting a predicate in the underlying programming languages such as SQL.
The database search engine executes the query with its predicate against the database to access and return records or objects having attributes that satisfy the specified query predicate.
There is a need in the art for improved techniques for generating query predicates from query conditions submitted by a user or application to form a database query to execute against the database.